Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix set visible devices #2174

Merged
merged 7 commits into from
May 12, 2021
Merged

Conversation

rijobro
Copy link
Contributor

@rijobro rijobro commented May 11, 2021

Fixes #2161.

Description

In TestTimeAugmentation, I called torch.cuda as a default argument to a constructor. This meant that the following code previously worked and now didn't:

import os
import monai
os.environ["CUDA_VISIBLE_DEVICES"] = '0'

I fixed the problem and also created a unit test to avoid it happening in the future. The trick is that we shouldn't call torch.cuda. during import monai.

Status

Ready

Types of changes

  • Non-breaking change (fix or new feature that would not break existing functionality).
  • New tests added to cover the changes.
  • Integration tests passed locally by running ./runtests.sh -f -u --net --coverage.
  • Quick tests passed locally by running ./runtests.sh --quick --unittests.
  • In-line docstrings updated.
  • Documentation updated, tested make html command in the docs/ folder.

rijobro added 2 commits May 11, 2021 14:11
Signed-off-by: Richard Brown <[email protected]>
Signed-off-by: Richard Brown <[email protected]>
Signed-off-by: Richard Brown <[email protected]>
Signed-off-by: Richard Brown <[email protected]>
@@ -89,7 +89,7 @@ def __init__(
batch_size: int,
num_workers: int,
inferrer_fn: Callable,
device: Optional[Union[str, torch.device]] = "cuda" if torch.cuda.is_available() else "cpu",
device: Union[str, torch.device] = torch.device("cpu"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To solve the flake8 issue, maybe you can default to a str "cpu", like what we did for MONAI metrics:
https://github.com/Project-MONAI/MONAI/blob/dev/monai/handlers/iteration_metric.py#L51

Thanks.

@rijobro rijobro enabled auto-merge (squash) May 12, 2021 15:11
@rijobro rijobro merged commit 6c0d8d7 into Project-MONAI:dev May 12, 2021
@rijobro rijobro deleted the visible_devices_fix branch May 12, 2021 15:55
yanielc pushed a commit to yanielc/MONAI that referenced this pull request May 13, 2021
fix set visible devices

Signed-off-by: Yaniel Cabrera <[email protected]>
yanielc pushed a commit to yanielc/MONAI that referenced this pull request May 13, 2021
fix set visible devices

Signed-off-by: Yaniel Cabrera <[email protected]>
wyli pushed a commit that referenced this pull request May 26, 2021
fix set visible devices
wyli pushed a commit that referenced this pull request May 26, 2021
fix set visible devices
wyli pushed a commit that referenced this pull request May 26, 2021
fix set visible devices
wyli pushed a commit that referenced this pull request May 26, 2021
fix set visible devices
wyli pushed a commit that referenced this pull request May 26, 2021
fix set visible devices
wyli pushed a commit that referenced this pull request May 27, 2021
fix set visible devices
wyli pushed a commit that referenced this pull request May 27, 2021
fix set visible devices
wyli pushed a commit that referenced this pull request May 27, 2021
fix set visible devices
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CUDA_VISIBLE_DEVICES environ setting not work in ver. 0.5.0
2 participants